--Game.SpiritRest("therock")

function gen_spirit_rest(data,par)
	if par == nil then par = data end
	local hint="<label=spirit_rest_last> "
	local name=""
	if par=="rage" then 
		hint=Attack.get_custom_param("rage")
	end 
	if par=="rest" then 
		hint=Attack.get_custom_param("rest")
	end 
	
	return " "..hint
end

function gen_lina_hint(data,par)
	if par == nil then par = data end
	local hint=Attack.get_custom_param(par)
	if hint==1 or hint=="1" then 
		return "<label=lina_yes>"
	else
		return "<label=lina_no>"
	end 
end

function gen_spirit_hint(data,par)
	if par == nil then par = data end
	local hint=""
	if par=="rage" then 
		hint=Attack.get_custom_param("rage")
	end 
	if par=="rest" then 
		hint=Attack.get_custom_param("rest")
	end 
	
	return " "..hint
end

function gen_spirit_level()
	local level=""
	
	return level
end


function gen_spirit_damage()

	local min, max = 0, 0
	for i=0, Logic.resistance()-1 do
	    local r = Logic.resistance(i)
	    local m = Attack.get_custom_param("damage."..r..".0")
	    if m ~= "" then
	        min = min + m
	        max = max + Attack.get_custom_param("damage."..r..".1")
	    end
	end
	if min==0 then
		min = Attack.get_custom_param("dmg.0")
		max = Attack.get_custom_param("dmg.1")
	end

	local pref = ""
	local dmg_coef = 1
	local lava_bonus_dam = tonumber(hero_item_count("sp_pet_lava_damage","count"))
	if Attack.atk_name() == "smash_hit" or Attack.atk_name() == "ball" or Attack.atk_name() == "dive" or Attack.atk_name() == "frenzy" or Attack.atk_name() == "lava" then
		dmg_coef = 1+hero_item_count("sp_pet_attack")/100
	end
	if Attack.atk_name() == "smash_hit" then
		dmg_coef = dmg_coef+hero_item_count("sp_pet_smash_attack")/100
	end
	if dmg_coef>1 or (Attack.atk_name() == "lava" and lava_bonus_dam >0) then
		pref = "<label=pet_param_green>"
		if Attack.atk_name() == "lava" and lava_bonus_dam >0 then 
			min = min + tonumber(lava_bonus_dam)
			max = max + tonumber(lava_bonus_dam)
		end
		min = min * dmg_coef
		if (min-math.floor(min))>.5 then min = math.ceil(min) else min = math.floor(min) end
		max = max * dmg_coef
		if (max-math.floor(max))>.5 then max = math.ceil(max) else max = math.floor(max) end
	end
	
	if min==max then 
		return pref..min 
	else
		return pref..min..'-'..max
	end

end

function gen_spirit_energo(data,par)
	if par == nil then par = data end
	local min, max = 0, 0
	if par=="mana" then
		min = Attack.get_custom_param("manabonus.0")
		max = Attack.get_custom_param("manabonus.1")
	else
		min = Attack.get_custom_param("ragebonus.0")
		max = Attack.get_custom_param("ragebonus.1")
  end 	
	if min==max then 
		return min 
	else
		return min..'-'..max
	end

end

function gen_spirit_param(data,par)
		if par == nil then par = data end 
		if par=="lvl" then
			local param = Attack.get_custom_param(par)
			if param=="1" then 
				return param
			else 
				return "1-"..param
			end 
		end
		if par=="push" then
			if hero_item_count("sp_pet_push")>0 then
				return "<label=pet_param_green>"..tostring(tonum(Attack.get_custom_param(par))+1)
			else 
				return tostring(Attack.get_custom_param(par))
			end
		end
		if par=="green" or par=="red" then
			if hero_item_count("sp_pet_digger")>0 then
				return "<label=pet_param_green>"..tostring(tonum(Attack.get_custom_param(par))+1)
			else
				return tostring(Attack.get_custom_param(par))
			end
		end
		if par=="health" then
			if hero_item_count("sp_pet_wall_health")>0 then
				local health = tonum(Attack.get_custom_param(par))*(1+hero_item_count("sp_pet_wall_health")/100)
				return "<label=pet_param_green>"..tostring(math.floor(health))
			else
				return tostring(Attack.get_custom_param(par))
			end
		end
		if par=="shock" then
			if hero_item_count("sp_pet_shock")>0 then
				local shock = tonum(Attack.get_custom_param(par))*(1+hero_item_count("sp_pet_shock")/100)
				return "<label=pet_param_green>"..tostring(math.floor(shock))
			else
				return tostring((Attack.get_custom_param(par)))
			end
		end
		if par=="charges" then
			if hero_item_count("sp_pet_charges")>0 then
				local charges = 3+hero_item_count("sp_pet_charges")
				charges = math.min(charges, 5)
				return "<label=pet_param_green>"..tostring(charges)
			else
				return "3"
			end
		end
		if par=="ap" then
			if hero_item_count("sp_pet_ap")>0 then
				return "<label=pet_param_green>"..tostring(tonum(Attack.get_custom_param(par))+hero_item_count("sp_pet_ap"))
			else 
				return tostring(Attack.get_custom_param(par))
			end
		end
		if par=="mana" then
			if hero_item_count("sp_pet_mana")>0 then
				local mana = tonum(Attack.get_custom_param(par))+hero_item_count("sp_pet_mana")
				mana = math.max(mana, 1)
				return "<label=pet_param_green>"..tostring(mana)
			else
				return tostring(Attack.get_custom_param(par))
			end
		end
		if par=="lead_sum" then
			
				local lead = tonumber(Attack.get_custom_param("lead"))
				local baselead = tonumber(Attack.get_custom_param("baselead"))
				local ld = Logic.hero_lu_item("leadership","count")
				local bonus_lead = hero_item_count("sp_pet_alien_egg_lead","count")
			if hero_item_count("sp_pet_alien_egg_lead")>0 then
				return "<label=pet_param_green>"..tostring(math.floor(((ld*lead/100)+baselead)*(1+bonus_lead/100)))
			else
				return tostring(math.floor(((ld*lead/100)+baselead)*(1+bonus_lead/100)))
			end
		end
		return Attack.get_custom_param(tostring(par))
end

function gen_pet_lvl(data,par)
		local lvl = tonumber(Attack.get_custom_param("lvl"))
		local par = ""
		if lvl==1 then par = "1" end 
		if lvl==2 then par = "1-2" end 
		if lvl==3 then par = "1-4" end 
		if lvl==4 then par = "2-5" end 
		
		return par
end

function gen_spirit_lead()
		local lead = tonumber(Attack.get_custom_param("lead"))
		local ld = Logic.hero_lu_item("leadership","count")
		return tostring(math.floor(ld*lead/100))
end

function gen_pet_fulllead()
		local lead = tonumber(Attack.get_custom_param("lead"))
		local baselead = tonumber(Attack.get_custom_param("baselead"))
		local ld = Logic.hero_lu_item("leadership","count")
		local bonus_lead = hero_item_count("sp_pet_alien_egg_lead","count")
		return tostring(math.floor(((ld*lead/100)+baselead)*(1+bonus_lead/100)))
end

function gen_spirit_sleep(par)
	local name = ""
	if par=="1" then 
		name = "therock"
	end 
	if par=="2" then 
		name = "slime"
	end 
	if par=="4" then 
		name = "death"
	end 
	if par=="3" then 
		name = "lina"
	end 
	return tostring(Game.SpiritRest(name))

end 